import { IChartSeriesFunnel } from '@ibiz/model-core';
import { ECElementEvent, FunnelSeriesOption, SeriesOption } from 'echarts';
import { BaseSeriesGenerator, CatalogData } from './base-series-generator';

/**
 * 漏斗图序列生成器
 * @author lxm
 * @date 2023-06-11 06:18:46
 * @export
 * @class FunnelSeriesGenerator
 * @extends {BaseSeriesGenerator<IChartSeriesFunnel>}
 */
export class FunnelSeriesGenerator extends BaseSeriesGenerator<IChartSeriesFunnel> {
  protected calcStaticOptions(): SeriesOption {
    const options = super.calcStaticOptions() as FunnelSeriesOption;

    options.label!.formatter = '{b}: {d}%({c})';
    options.label!.position = 'outer';

    return options;
  }

  protected calcSeriesData(catalogData: CatalogData): {
    name: string;
    value: IData[];
  }[] {
    return Object.keys(catalogData).map(catalog => {
      const data = catalogData[catalog];
      return { name: catalog, value: [data.value, data.deData?.srfkey] };
    });
  }

  getSrfkeyByParams(params: ECElementEvent): string {
    return (params.value as IData)[1];
  }
}
